package com.xhwl.data.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.common.pojo.cent.sdata.personnel.StaffBusinessType;
import com.xhwl.common.query.cent.sdata.personal.StaffBusinessTypeQuery;
import com.xhwl.common.utils.StringUtils;
import com.xhwl.data.service.personal.IStaffBusinessTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: 企业通讯录业务类型配置
 * @author: linruipeng
 * @create: 2022-05-20 10:30
 **/
@RestController
public class StaffBusinessTypeController {

    @Autowired
    private IStaffBusinessTypeService staffBusinessTypeService;

    /**
     * 分页查询
     * @param staffBusinessTypeQuery
     * @param page
     * @return
     */
    @GetMapping("/staff-business-type/page")
    public ResultJson page(StaffBusinessTypeQuery staffBusinessTypeQuery, Page page) {
        Page page1 = staffBusinessTypeService.page(staffBusinessTypeQuery, page);
        return ResultJson.success(page1);
    }


    /**
     * 列表查询
     * @param staffBusinessTypeQuery
     * @return
     */
    @GetMapping("/staff-business-type/list")
    public ResultJson list(StaffBusinessTypeQuery staffBusinessTypeQuery) {
        return ResultJson.success(staffBusinessTypeService.list(staffBusinessTypeQuery));
    }


    /**
     * 新增
     * @param staffBusinessType
     * @return
     */
    @PostMapping("/staff-business-type/create")
    public ResultJson create(@RequestBody StaffBusinessType staffBusinessType) {
        if (null == staffBusinessType.getName() || StringUtils.isEmpty(staffBusinessType.getName())) {
            return ResultJson.fail("参数错误");
        }
        return staffBusinessTypeService.create(staffBusinessType);
    }


    /**
     * 修改
     * @param staffBusinessType
     * @return
     */
    @PostMapping("/staff-business-type/update")
    public ResultJson update(@RequestBody StaffBusinessType staffBusinessType) {
        if (null == staffBusinessType.getName() || StringUtils.isEmpty(staffBusinessType.getName())) {
            return ResultJson.fail("参数错误");
        }
        if (null == staffBusinessType.getId()) {
            return staffBusinessTypeService.create(staffBusinessType);
        } else {
            return staffBusinessTypeService.update(staffBusinessType);
        }
    }


    /**
     * 获取详情
     * @param id
     * @return
     */
    @GetMapping("/staff-business-type/detail")
    public ResultJson detail(Integer id) {
        return staffBusinessTypeService.getOne(id);
    }

}
